function Gd(id="gdcontainer"){
    this.id = id;

    //计算容器的宽度（为了防止内容溢出）
    this.calcContainWidth = function (){
        const content = $('#'+id+" .gd-content")[0];
        const firstItem = $(content).children().first();
        const itemWidth = firstItem.outerWidth(true);
        const containerwidth = itemWidth * $(content).children().length;
        return containerwidth;
    }

    //克隆滚动元素
    this.cloneScrollItem = function (){
        const content = $('#'+id+" .gd-outer");
        const items = content.children().clone();
        content.append(items);
    }

    //设置滚动速度
    this.gdAccelerate = function (num = 5){
        for(let i=0; i<$('#'+id+' .gd-content').length;i++){
            let item = $('#'+id+' .gd-content')[i];
            item.style.animationDuration = num/100+"s";
        }
    }

    //停止滚动
    this.gdStop = function gdStop(){
        $('#'+id+" .gd-content").css("animation","none");
    }
    //开始滚动
    this.gdStart = function (){
        this.gdAccelerate(1000);
    }

    //初始化
    this.gdInit = function (){
        const width = this.calcContainWidth(id);
        $("#"+id).css("width",width)
        this.cloneScrollItem(id);
    }

    //重新计算容器宽度
    this.gdreset = function(){
        this.calcContainWidth();
        this.cloneScrollItem();
        this.gdInit();
    }
    this.gdInit();
}



